import { sys } from "cc";

export class SDKTools {
    public static isdebug = 0;

    //@ts-ignore
    public static isKSGame = typeof KSGameGlobal != 'undefined' && sys.platform == sys.Platform.WECHAT_GAME;
    //@ts-ignore
    public static isWeChat = sys.platform == sys.Platform.WECHAT_GAME && typeof KSGameGlobal == 'undefined'
    public static isByteDance = sys.platform == sys.Platform.BYTEDANCE_MINI_GAME;
    public static isAliPay = sys.platform == sys.Platform.ALIPAY_MINI_GAME;
    public static get hmCheck(): boolean {
        return SDKTools.OniOSMiniGame || SDKTools.isKSGame
    }
    public static get appid(): string {
        if (this.isWeChat) {
            return "wx8d5d8f9f6b3e5e8b";
        } else if (this.isByteDance) {
            return "tt6c0b2b3f3e5e5f8b";
        } else if (this.isAliPay) {
            return "2021005129669112";
        } else if (this.isKSGame) {
            //@ts-ignore
            if(KSGameGlobal["appidConfig"]){
                 //@ts-ignore
                return KSGameGlobal["appidConfig"];
            }
            return "ks665406848553849654";
        } else {
            return "ks665406848553849654";
        }
    }

    public static get skdName(): string {
        if (this.isWeChat) {
            return "wx";
        } else if (this.isByteDance) {
            return "tt";
        } else if (this.isAliPay) {
            return "aliPay";
        } else if (this.isKSGame) {
            return "ks";
        } else {
            return "ks";
        }
    }

    public static get OniOSMiniGame(): boolean {
        if (this.isdebug) return false
        let res = sys.os == sys.OS.IOS
        console.log("OniOSMiniGame",res)
        return res;
    }
    public static get NowTime() {
        return Math.floor(new Date().getTime() / 1000);
    }
    static IsToday(time: number) {
        let date = new Date(time);
        let now = new Date();
        if (date.getFullYear() == now.getFullYear() && date.getMonth() == now.getMonth() && date.getDate() == now.getDate()) {
            return true;
        }
        return false;
    }

    public static get m_ADClass() {
        if (this.isWeChat) {
            //@ts-ignore
            return wx;
        } else if (this.isByteDance) {
            //@ts-ignore
            return tt
        } else if (this.isAliPay) {
            //@ts-ignore
            return my
        } else if (this.isKSGame) {
            //@ts-ignore
            return wx
        }
    }

    public static SavaData(key: string, data: any) {
        sys.localStorage.setItem(key, JSON.stringify(data));
    }

    public static GetData(key: string, mr: any = null) {
        let data = sys.localStorage.getItem(key);
        if (data === undefined || data === null || data === 'NaN' || data === '') {
            return mr;
        }
        return JSON.parse(data);
    }

    // 获取中文大写数字
    public static GetShuZi(index: number): string {
        let shuzi = ["零", "一", "二", "三", "四", "五", "六", "七", "八", "九", "十"];
        return shuzi[index];
    }

    
    public static GetTitle(): string {
        //@ts-ignore
        if (this.isKSGame && KSGameGlobal["Title"]) {
            //@ts-ignore
            return KSGameGlobal["Title"];
            // KSGameGlobal["appidConfig"] = "ks665406848553849654";
        }
        return "开心消消乐";
    }

    // 获取软著信息
    public static GetSoftInfo(): string {
        //@ts-ignore
        if (this.isKSGame && KSGameGlobal["SoftInfo"]) {
            //@ts-ignore
            return KSGameGlobal["SoftInfo"];
            // KSGameGlobal["appidConfig"] = "ks665406848553849654";
        }  
        return "©2023 开心消消乐";
    }
}